# -*- coding: utf-8 -*-
"""
@Time    : 2022/9/16 09:55
@Author  : huanghuang
"""
import enum
from typing import List, Any

from pydantic import BaseModel, Field, root_validator


class UseNameOrIndexEnum(enum.Enum):
    name = "name"
    index = "index"


class GenerateExcelRequestModel(BaseModel):
    header: List[str] = Field(..., description="生成的excel的header行")
    data: List[List[Any]] = Field(None, description="生成的excel的数据行")
    sheet_name: str = Field(None, max_length=32,  description="sheet的名字")
    filename: str = Field(None, max_length=32,  description="api接口的时候,希望返回的文件名")


class GeneratePdfRequestModel(BaseModel):
    url: str = Field(None, max_length=1024, description="链接")
    html: str = Field(None, max_length=10 * 1024 * 1024, description="html文件内容 最大10MB")
    callback_url: str = Field(None, max_length=1024, description="回调url,如果设置了则会异步返回，如果有参数，最好是在url里面携带")

    @root_validator(pre=True)
    def pre_validate(cls, attr: dict):
        url = attr.get("url")
        html = attr.get("html")
        if not any([url, html]):
            raise ValueError("缺失参数")
        return attr

